<?php
$this->headTitle($this->translate('Group floor'));
$this->headLink()
    ->appendStylesheet($this->STATIC_URL. '/styles/people/floor.css');
?>
<div class="rui-d5f">
<h3>
    <?php echo $this->group->getVillage()->name .$this->group->name?>
    [ <a href="<?php echo $this->url(array(
        'controller'=> 'family',
        'action'=> 'manage',
        'gid'=> $this->group->gid))?>">查看列表</a> ]
</h3>
<div>
   <?php echo $this->group->getVillage()->name?>
    总人口：<?php echo $this->group->getVillage()->population?>
    已婚育龄妇女人数：<?php echo $this->group->getVillage()->popu_women?>
    流动人口：<?php echo $this->group->getVillage()->popu_flow?>
    社区管理员：<?php echo $this->group->getVillage()->master?>
</div>

<div id="floorsWrap"></div>

<p>
	<button onclick="location.href='<?php echo $this->url(array(
        'controller'=> 'group',
		'action'=> 'index',
		'aid'=> $this->group->getVillage()->aid
		))?>'"><?php echo $this->translate('Back to group index')?></button>
</p>
</div>

<script type="text/javascript">
$(function(){
<?php foreach ($this->floors as $f=>$floor): ?>
<?php if(is_numeric($floor->family)){
    $unitsFamily = array();
    for($i=0;$i<$floor->units;$i++){
        $unitsFamily[] = $floor->family;
    }
    $floor->family = implode(',', $unitsFamily);
}?>
createFloors(<?php echo $floor->number?>,<?php echo $floor->units?>,<?php echo $floor->level?>,[<?php echo $floor->family?>]);
<?php endforeach;?>
var familyArray = new Array();
<?php foreach ($this->entries as $f=>$family): ?>
familyArray[<?php echo $f?>] = [["<?php echo implode('","',$family[0])?>"],["<?php echo $family[1]['name']?>","<?php echo $family[1]['pid']?>","<?php echo $family[1]['measure']?>","<?php echo $family[1]['management_type']?>"]];
<?php endforeach;?>
for(var i=0;i<familyArray.length;i++){
    insertFamily(familyArray[i][0],familyArray[i][1]);
}
    $(".unit-floor li div :hidden[value='男性绝育术']").parent().attr('title','男性绝育术').css("border","2px solid blue");
    $(".unit-floor li div :hidden[value='女性绝育术']").parent().attr('title','女性绝育术').css("border","2px solid red");
    $(".unit-floor li div :hidden[value$='宫内节育器']").parent().attr('title','宫内节育器').css("border","2px solid green");
    
    $(".unit-floor li div :hidden[value$='在职职工']").next("a").attr('title','在职职工').css("color","blue");
    $(".unit-floor li div :hidden[value$='无业']").next("a").attr('title','无业').css("color","red");

});

function createFloors(number,units,floor,family) {
    var unitsHTML = '';
    for(var u=1;u<= units;u++){
        unitsHTML += '<td><div class="unit-wrap unit-'+u+'">';
        unitsHTML += '<dl class="unit-floor path-'+family[u-1]+'"><dt>'+u+'单元</dt><dd><ol>';
        var floorHTML = '';
        for(var l=1;l<=floor;l++) {
            floorHTML += '<li class="floor-level-'+l+'">';
            var familyHTML = '';
            for(var f=1;f<=family[u-1];f++) {
                familyHTML += '<div class="floor-path-'+f+'"><span class="nobody">无人居住</span></div>';
            }
            floorHTML += familyHTML+'</li>';
        }
        unitsHTML += floorHTML+'</ol></dd></dl></div></td>';
    }
    
    var FloorsHTML = '<fieldset id="floor-'+number+'" class="level-'+floor+'"><legend>'+number+'号楼</legend>';
    FloorsHTML += '<table border="0" cellspacing="0" cellpadding="0">';
    FloorsHTML += '<tr class="roof">';
    FloorsHTML += '<td class="roof-left" width="94"></td>';
    FloorsHTML += '<td class="roof-center">&nbsp;</td>';
    FloorsHTML += '<td class="roof-right" width="94"></td>';
    FloorsHTML += '</tr>';
    FloorsHTML += '<tr><td colspan="3" style="padding:0 40px">';
    FloorsHTML += '<table border="0" cellspacing="0" cellpadding="0"><tr>';
    FloorsHTML += unitsHTML;
    FloorsHTML += '</tr></table>';
    FloorsHTML += '</td></tr></table></fieldset>';
    
    //return FloorsHTML;
    $("#floorsWrap").append(FloorsHTML);
}
function insertFamily(floor,family) {
    $("#floor-"+floor[1]+" .unit-"+floor[2]+" .floor-level-"+floor[3]+" .floor-path-"+floor[4])
    .html('<input type="hidden" value="'+family[2]+'" /><input type="hidden" value="'+family[3]+'" /><a href="<?php echo $this->url(array('action'=> 'browse'))?>/pid/'+family[1]+'">'+family[0]+'</a>');
}
</script>
